//package com.jml.zlhq.app.ui;
//
//import java.io.InputStream;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import org.apache.http.Header;
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import android.app.Activity;
//import android.app.Dialog;
//import android.content.Context;
//import android.content.Intent;
//import android.database.Cursor;
//import android.net.Uri;
//import android.os.Bundle;
//import android.provider.MediaStore;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup;
//import android.view.ViewGroup.LayoutParams;
//import android.widget.AutoCompleteTextView;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//
//import com.jml.zlhq.app.R;
//import com.jml.zlhq.app.URLs;
//import com.jml.zlhq.app.bean.UserEntry;
//import com.jml.zlhq.app.lib.wheelchoose.MyAlertDialog;
//import com.jml.zlhq.app.lib.wheelcitychoose.AbstractWheelTextAdapter;
//import com.jml.zlhq.app.service.HttpService;
//import com.jml.zlhq.app.util.BaseTools;
//import com.jml.zlhq.app.util.StringUtil;
//import com.jml.zlhq.app.util.UIUtil;
//import com.jml.zlhq.app.widgets.CommonDialog;
//import com.jml.zlhq.app.widgets.RoundImageView;
//import com.loopj.android.http.TextHttpResponseHandler;
//import com.nostra13.universalimageloader.core.ImageLoader;
//
//public class UserInfoActivity extends BaseActivity {
//	private LinearLayout userInfoTag,name,city;
//	private TextView nameText,cityText,userTag;
//	private ImageView userHead;
//	private UserEntry user;
//	private String pac = "";
//	private String pap = "";
//	private String pacid,papid;
//	private Button sub;
//	
//	@Override
//	protected void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.user_info_activity);
//		
//		LinearLayout leftLay = (LinearLayout) findViewById(R.id.content_header_left_lay);
//		LinearLayout rightLay = (LinearLayout) findViewById(R.id.content_header_right_lay);
//		leftLay.setOnClickListener(this);
//		rightLay.setOnClickListener(this);
//		AutoCompleteTextView centerEdit = (AutoCompleteTextView) findViewById(R.id.content_header_center_edit);
//		centerEdit.setVisibility(View.GONE);
//		ImageView leftImage = (ImageView) findViewById(R.id.content_header_left_img);
//		leftImage.setImageResource(R.drawable.back_selector);
//		ImageView roghtImage1 = (ImageView) findViewById(R.id.content_header_right_img);
//		roghtImage1.setVisibility(View.GONE);
//		TextView centerText = (TextView) findViewById(R.id.content_header_center_text);
//		centerText.setText("个人信息");
//		TextView rightText = (TextView) findViewById(R.id.content_header_right_text);
//		rightText.setVisibility(View.INVISIBLE);
//		TextView cityChosed = (TextView) findViewById(R.id.content_header_center_text2);
//		cityChosed.setVisibility(View.GONE);
//		
//		user = appContext.getLoginUser();
//		
//		sub = (Button) findViewById(R.id.user_info_sub);
//		userTag = (TextView) findViewById(R.id.user_info_tag_content);
//		userInfoTag = (LinearLayout) findViewById(R.id.user_info_tag);
//		name = (LinearLayout) findViewById(R.id.user_info_name_lay);
//		city = (LinearLayout) findViewById(R.id.user_info_city_lay);
//		nameText = (TextView) findViewById(R.id.user_info_name);
//		cityText = (TextView) findViewById(R.id.user_info_city);
//		userHead = (RoundImageView) findViewById(R.id.user_info_ico);
//		userInfoTag.setOnClickListener(this);
//		userHead.setOnClickListener(this);
//		name.setOnClickListener(this);
//		city.setOnClickListener(this);
//		sub.setOnClickListener(this);
//		
//		loadData(null);
//	}
//
//	@Override
//	public void loadData(Map<String, String> param) {
//		nameText.setText(user.getUserName());
//		cityText.setText(user.getUserCity());
//		if(!StringUtil.isEmpty(user.getUserTag()))userTag.setText(user.getUserTag());
//		ImageLoader.getInstance().displayImage(user.getUserImage(), userHead, UIUtil.getImageLoaderDisplayOptions(R.drawable.icon_touxiang110));
//	}
//
//	@Override
//	public void clearData() {}
//	
//	@Override
//	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//		super.onActivityResult(requestCode, resultCode, data);
//		if(requestCode==2&&Activity.RESULT_OK==resultCode&&null!=data){
//			Uri selectedImage = data.getData();
//			String picturePath;
//			try {
//				String[] filePathColumns={MediaStore.Images.Media.DATA};
//				Cursor c = this.getContentResolver().query(selectedImage, filePathColumns, null,null, null);
//				c.moveToFirst();
//				int columnIndex = c.getColumnIndex(filePathColumns[0]);
//				picturePath= c.getString(columnIndex);
//				c.close();
//			} catch (Exception e) {
//				picturePath = selectedImage.getPath();
//			}
//			
//			Bundle bdl = new Bundle();
//			bdl.putString("image", picturePath);
//			UIUtil.openActivity(activity, PicCutActivity.class, bdl, 3);
//
//		}else if(requestCode==3&&Activity.RESULT_OK==resultCode){
//			Map<String, String> map = new HashMap<String, String>();
//			map.put("auth_token", appContext.getLoginUid());
//			HttpService.getByText(URLs.USER_INFO, map, new TextHttpResponseHandler() {
//				
//				@Override
//				public void onSuccess(int arg0, Header[] arg1, String arg2) {
//					Log.i("=====", arg2);
//					try {
//						JSONObject result = new JSONObject(arg2);
//						if(result.getInt("status")==0){
//							UserEntry userodl = appContext.getLoginUser();
//							UserEntry user = new UserEntry(BaseTools.getFrom("data._id", result), BaseTools.getFrom("data.name", result), null, BaseTools.getFrom("data.logo_url", result), userodl.getToken(), BaseTools.getFrom("data.location", result), BaseTools.getFrom("data.description", result));
//							appContext.Login(user);
//							ImageLoader.getInstance().displayImage(user.getUserImage(), userHead, UIUtil.getImageLoaderDisplayOptions(R.drawable.icon_touxiang110));
//							return;
//						}
//					} catch (JSONException e) {
//						e.printStackTrace();
//					}
//				}
//				
//				@Override
//				public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
//					
//				}
//			});
//		}else if(requestCode==5){
//			user = appContext.getLoginUser();
//			if(!StringUtil.isEmpty(user.getUserTag())){
//				userTag.setText(user.getUserTag());
//			}
//		}
//	}
//	
//
//	@Override
//	public void onClick(View view) {
//		switch (view.getId()) {
//		case R.id.user_info_sub:
//		case R.id.content_header_left_lay:
//			finish();
//			break;
//		case R.id.user_info_ico:
////			Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
////		    intent.addCategory(Intent.CATEGORY_OPENABLE);
////		    intent.setType("image/*");
////		    intent.putExtra("crop", "true");
////		    intent.putExtra("aspectX", 1);
////		    intent.putExtra("aspectY", 1);
////		    intent.putExtra("outputX", 80);
////		    intent.putExtra("outputY", 80);
////		    intent.putExtra("return-data", true);
////
////		    startActivityForResult(intent, 3);
//		    Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);//调用android的图库 
//		    startActivityForResult(i, 2); 
//			break;
//		case R.id.user_info_tag:
//			UIUtil.openActivity(this, UserTagActivity.class, null,5);
//			break;
//		case R.id.user_info_name_lay:
//			CommonDialog dialog = new CommonDialog(activity, true);
//			final EditText nameIn = new EditText(dialog.getContext());
//			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
//			lp.setMargins(UIUtil.dip2px(appContext, 10), UIUtil.dip2px(appContext, 5), UIUtil.dip2px(appContext, 10), UIUtil.dip2px(appContext, 5));
//			nameIn.setLayoutParams(lp);
//			nameIn.setBackgroundResource(R.drawable.fillet_border_fff);
//			dialog.show(true, true, false, "请输入昵称", "", "保存", "取消", new android.view.View.OnClickListener() {
//				@Override
//				public void onClick(View view) {
//					final String str = nameIn.getText().toString();
//					if(StringUtil.isEmpty(str)){
//						UIUtil.ToastMessage(appContext, "不能为空");
//						return;
//					}
//					((CommonDialog)view.getTag()).dismiss();
//					Map<String, String> map = new HashMap<String, String>();
//					map.put("auth_token", appContext.getLoginUid());
//					map.put("value", str);
//					final Dialog  mProDialog =  UIUtil.showLoadingDialog(activity, "提交中，请稍后...", false);
//					HttpService.postByText(URLs.USER_INFO_NAME, map, new TextHttpResponseHandler() {
//						
//						@Override
//						public void onSuccess(int arg0, Header[] arg1, String arg2) {
//							mProDialog.dismiss();
//							Log.i("====", arg2);
//							try {
//								JSONObject json = new JSONObject(arg2);
//								if(json.getInt("status")==0){
//									nameText.setText(str);
//									user.setUserName(str);
//									appContext.Login(user);
//									WodeFragment.freshPage = true;
//									return;
//								}
//							} catch (JSONException e) {
//								e.printStackTrace();
//							}
//							UIUtil.ToastMessage(appContext, "保存失败");
//						}
//						
//						@Override
//						public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
//							mProDialog.dismiss();
//							UIUtil.ToastMessage(appContext, "保存失败");
//						}
//					});
//				}
//			}, null);
//			dialog.addContent(nameIn);
//			break;
//		case R.id.user_info_city_lay:
//			pap="";
//			pac="";
//			pacid = "";
//			papid = "";
//			View contentView = LayoutInflater.from(this).inflate(R.layout.wheelcity_cities_layout, null);
//			final com.jml.zlhq.app.lib.wheelcitychoose.WheelView province = (com.jml.zlhq.app.lib.wheelcitychoose.WheelView) contentView.findViewById(R.id.wheelcity_province);
//			final com.jml.zlhq.app.lib.wheelcitychoose.WheelView city = (com.jml.zlhq.app.lib.wheelcitychoose.WheelView) contentView.findViewById(R.id.wheelcity_city);
//			final List<JSONObject> provincelist = new ArrayList<JSONObject>();
//			final List<JSONObject> citylist = new ArrayList<JSONObject>();
//			try {
//				InputStream is = this.getResources().openRawResource(R.raw.provinces);
//				byte[] buffer = new byte[is.available()];
//				is.read(buffer);
//
//				String json = new String(buffer, "UTF-8");
//				JSONArray provinces = new JSONArray(json);
//				for (int j = 0; provinces!=null && j < provinces.length(); j++) {
//					provincelist.add(provinces.getJSONObject(j));
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			
//			papid = BaseTools.getFrom("id", provincelist.get(0));
//			pap = BaseTools.getFrom("name", provincelist.get(0));
//			province.setViewAdapter(new CountryAdapter(activity,provincelist));
//			
//			try {
//				citylist.clear();
//				JSONArray citys = provincelist.get(0).getJSONArray("citys");
//				for (int j = 0; citys!=null && j < citys.length(); j++) {
//					citylist.add(citys.getJSONObject(j));
//				}
//				pacid = citylist.get(0).keys().next();
//				pac = BaseTools.getFrom(pacid, citylist.get(0));
//
//				updateCities(city, citylist, 0);
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			
//			
//			province.addChangingListener(new com.jml.zlhq.app.lib.wheelcitychoose.OnWheelChangedListener() {
//				public void onChanged(com.jml.zlhq.app.lib.wheelcitychoose.WheelView wheel, int oldValue, int newValue) {
//					try {
//						papid = BaseTools.getFrom("id", provincelist.get(province.getCurrentItem()));
//						pap = BaseTools.getFrom("name", provincelist.get(province.getCurrentItem()));
//						citylist.clear();
//						JSONArray citys = provincelist.get(province.getCurrentItem()).getJSONArray("citys");
//						for (int j = 0; citys!=null && j < citys.length(); j++) {
//							citylist.add(citys.getJSONObject(j));
//						}
//						pacid = citylist.get(0).keys().next();
//						pac = BaseTools.getFrom(pacid, citylist.get(0));
//						updateCities(city, citylist, newValue);
//						//cityTxt = DataUtil.getMap2Str2(citys.get(city.getCurrentItem()),"name");
//						//Integer.parseInt(DataUtil.getMap2Str2(citys.get(city.getCurrentItem()),"id"));
//					} catch (Exception e) {
//						e.printStackTrace();
//					}
//					
//				}
//			});
//
//			city.addChangingListener(new com.jml.zlhq.app.lib.wheelcitychoose.OnWheelChangedListener() {
//				public void onChanged(com.jml.zlhq.app.lib.wheelcitychoose.WheelView wheel, int oldValue, int newValue) {
//					try {
//						pacid = citylist.get(city.getCurrentItem()).keys().next();
//						pac = BaseTools.getFrom(pacid, citylist.get(city.getCurrentItem()));
//						//Integer.parseInt(DataUtil.getMap2Str2(citys.get(city.getCurrentItem()),"id"));
//					} catch (Exception e) {
//						e.printStackTrace();
//					}
//				}
//			});
//			
//			final MyAlertDialog dialogcity = new MyAlertDialog(this)
//				.builder()
//				//.setTitle(city.getText().toString())
//				// .setMsg("再连续登陆15天，就可变身为QQ达人。退出QQ可能会使你现有记录归零，确定退出？")
//				// .setEditText("1111111111111")
//				.setView(contentView).setCanceledOnTouchOutside(true);
//				dialogcity.setPositiveButton("确定", new OnClickListener() {
//					@Override
//					public void onClick(View v) {
//						if(StringUtil.isEmpty(pac)||pac.indexOf("请选择")>-1||StringUtil.isEmpty(pap)||pap.indexOf("请选择")>-1){
//							UIUtil.ToastMessage(activity, "选择不正确");
//						}else{
//							Map<String, String> map = new HashMap<String, String>();
//							map.put("auth_token", appContext.getLoginUid());
//							map.put("value", papid);
//							map.put("value2", pacid);
//							final Dialog  mProDialog =  UIUtil.showLoadingDialog(activity, "提交中，请稍后...", false);
//							HttpService.postByText(URLs.USER_INFO_LOCATE, map, new TextHttpResponseHandler() {
//								
//								@Override
//								public void onSuccess(int arg0, Header[] arg1, String arg2) {
//									mProDialog.dismiss();
//									Log.i("====", arg2);
//									try {
//										JSONObject json = new JSONObject(arg2);
//										if(json.getInt("status")==0){
//											cityText.setText(pap+"-"+pac);
//											user.setUserCity(pap+"-"+pac);
//											appContext.Login(user);
//											dialogcity.dismiss();
//											WodeFragment.freshPage = true;
//											return;
//										}
//									} catch (JSONException e) {
//										e.printStackTrace();
//									}
//									UIUtil.ToastMessage(appContext, "保存失败");
//								}
//								
//								@Override
//								public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
//									mProDialog.dismiss();
//									UIUtil.ToastMessage(appContext, "保存失败");
//								}
//							});
//						}
//					}
//				});
//			dialogcity.show();
//			break;
//		default:
//			break;
//		}
//	}
//
//	private void updateCities(final com.jml.zlhq.app.lib.wheelcitychoose.WheelView city, final List<JSONObject> citys, final int index) {
//		ArrayWheelAdapter cityAdapter = new ArrayWheelAdapter(UserInfoActivity.this, citys);
//		cityAdapter.setTextSize(18);
//		city.setViewAdapter(cityAdapter);
//	}
//	
//	public class ArrayWheelAdapter extends AbstractWheelTextAdapter {
//	    
//	    // items
//	    private List<JSONObject> items;
//
//	    /**
//	     * Constructor
//	     * @param context the current context
//	     * @param items the items
//	     */
//	    public ArrayWheelAdapter(Context context, List<JSONObject> items) {
//	        super(context);
//	        
//	        //setEmptyItemResource(TEXT_VIEW_ITEM_RESOURCE);
//	        this.items = items;
//	    }
//	    
//		@Override
//	    public CharSequence getItemText(int index) {
//	        if (index >= 0 && index < items.size()) {
//	            return BaseTools.getFrom(items.get(index).keys().next(), items.get(index));
//	        }
//	        return null;
//	    }
//
//	    @Override
//	    public int getItemsCount() {
//	        return items==null?0:items.size();
//	    }
//	}
//	
//	private class CountryAdapter extends com.jml.zlhq.app.lib.wheelcitychoose.AbstractWheelTextAdapter {
//		// Countries names
//		private List<JSONObject> provinces;
//
//		/**
//		 * Constructor
//		 */
//		protected CountryAdapter(Context context,List<JSONObject> provinces) {
//			super(context, R.layout.wheelcity_country_layout, NO_RESOURCE);
//			setItemTextResource(R.id.wheelcity_country_name);
//			this.provinces = provinces;
//		}
//
//		@Override
//		public View getItem(int index, View cachedView, ViewGroup parent) {
//			View view = super.getItem(index, cachedView, parent);
//			return view;
//		}
//
//		@Override
//		public int getItemsCount() {
//			return provinces==null?0:provinces.size();
//		}
//
//		@Override
//		protected CharSequence getItemText(int index) {
//			try {
//				return BaseTools.getFrom("name", provinces.get(index));
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			return "";
//		}
//	}
//	
//}
